import Vue from 'vue'

const sw = {
  state: () => ({
    errorModelIsShow: false,
  }),
  mutations: {
    setErrorModelIsShow(state, status) {
      state.errorModelIsShow = status
    }
  },
  actions: {
    showModel({ commit, state }){
      if(!state.errorModelIsShow){
        commit('setErrorModelIsShow',true)
        Vue.prototype.$popup.show({
          type: 'confirm-img',
          success: (popup) => {
            popup.$on('confirm', async () => {
              Vue.prototype.$popup.hide('confirm-img')
              commit('setErrorModelIsShow',false)
              // 跳转安卓联网页面
              const { android } = window
              android.toNetSetting()
            })
            popup.$on('cancel', async () => {
              Vue.prototype.$popup.hide('confirm-img')
              commit('setErrorModelIsShow',false)
            })
            popup.setData({
              icon:'network.png',
              content: '请先连接网络',
              confirmText: '去连接'
            })
          },
        })
      }
    }
  }
}

export default sw
